package com.nobradovic83.pygsto.service.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import com.nobradovic83.pygsto.service.Get;


public class GetImpl<Type> extends HibernateDaoSupport implements Get<Type>{

	private Class<Type> type;
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<Type> execute() {
		Criteria criteria = getManager().createCriteria(getType());
		return criteria.list();
	}

	protected Session getManager() {
		return getSessionFactory().getCurrentSession();
	}

	public Get<Type> setType(Class<Type> clazz) {
		this.type = clazz;
		return this;
	}

	public Class<Type> getType() {
		return type;
	}

}
